package com.road2trip.gwt.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.SuggestBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.road2trip.gwt.client.tools.Redirect;

/** 
 * Entry point for the search page 
 */
public class EPMapSearch implements EntryPoint {

	private SuggestBox suggestbox;

	
	@Override
	public void onModuleLoad() {
		// TODO Auto-generated method stub
		VerticalPanel panel = new VerticalPanel();
		suggestbox = new SuggestBox(new MapSuggestOracle());
		panel.add(new Label("Where?"));
		panel.add(suggestbox);
		panel.add(new Button("ok", new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				final String place = suggestbox.getValue();
				GWT.log(place, null);
				
				String url = GWT.getHostPageBaseURL() + "p/?name=" + place;
				GWT.log(url, null);
				
				Redirect.toURL(url);
			}
		}));
		RootPanel.get("search").add(panel);
	}

}
